package com.interceptor;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.util.HttpUtil;



public class LoginInterceptor extends HandlerInterceptorAdapter {
	
	static Logger log = Logger.getLogger(
			LoginInterceptor.class.getName());
	private Cache ehcache;
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//		String user = request.getHeader("userName");
//		String userId = request.getHeader("userId");
//		String token = request.getHeader("token");
//		if(request.getRequestURI().contains("login")){
//			return true;
//		}
//		Element e = ehcache.get(userId);
//		if (e!=null&&token.equals(e.getObjectValue())) {
		log.info(request.getHeader("currentId")+" "+HttpUtil.getVisitorIp(request)+" "+request.getRequestURI());
		System.out.println(request.getHeader("currentId")+" "+HttpUtil.getVisitorIp(request)+" "+request.getRequestURI());
		System.out.println(request.getRequestURI().substring(request.getRequestURI().lastIndexOf("/"),request.getRequestURI().length()));
		return true;
//		}
//		return false;
	}
		public Cache getEhcache() {
			return ehcache;
		}
		public void setEhcache(Cache ehcache) {
			this.ehcache = ehcache;
		}


}
	